package com.xiaomei.manager.web.controller;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.servlet.Servlet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aliyun.oss.common.utils.ResourceManager;
import com.xiaomei.manager.model.SysOrganization;
import com.xiaomei.manager.model.SysResource;
import com.xiaomei.manager.service.IOrganizationService;
import com.xiaomei.manager.service.IResourceService;

@Controller
public class TestController {
	@Autowired
	private IOrganizationService organizationService;
	@Autowired
	private IResourceService resourceService;
	
	@RequestMapping(value="/test")
	@ResponseBody
	public String test(){
		SysOrganization sys = new SysOrganization();
		sys.setName("长沙分公司");
		sys.setParentId(1l);
		sys.setParentIds("0/1/");
		sys.setAvailable(true);
		
		organizationService.createOrganization(sys);
		List<SysOrganization> ok = organizationService.findAll();
		System.out.print(ok.get(0).getName());
		System.out.print(organizationService.findOne(5l).getName());
		sys.setId(5l);
		List<SysOrganization> ok1 = organizationService.findAllWithExclude(sys);
		for(SysOrganization sys1:ok1){
			System.out.println(sys1.getName());
		}
		for(SysOrganization sys1:ok){
			System.out.println(sys1.getName());
		}
		System.out.print(ok1.get(0).getName());
		
		SysResource sysr = new SysResource();
		sysr.setAvailable(false);
		sysr.setName("abc");
		sysr.setParentId(41l);
		sysr.setParentIds("0/1/41/");
		sysr.setPermission("role:create");
		sysr.setType(SysResource.ResourceType.button);
		sysr.setUrl("/role");
		resourceService.createResource(sysr);
		List<SysResource> ok2 = resourceService.findAll();
		for(SysResource sys1:ok2){
			System.out.println(sys1.getName());
		}
		System.out.print(resourceService.findOne(1l).getName());
		Set<String> set = new HashSet<String>();
		set.add("user:view");
		List<SysResource> re = resourceService.findMenus(set);
		for(SysResource sysr1 : re){
			System.out.println(sysr1.getName());
			System.out.println(sysr1.getParentIds());
			
		}
		Set<Long> set1 = new HashSet<Long>();
		set1.add(1l);
		set1.add(2l);
		Set<String> ok5 = resourceService.findPermissions(set1);
		Iterator<String> it = ok5.iterator();
		while(it.hasNext()){
			System.out.println(it.next());
		}
		
		return "ok";
	}
	
	
	
}
